<?php
/**
 * Created by PhpStorm.
 * User: suncco
 * Date: 2018/8/7
 * Time: 17:48
 */

namespace app\admin\validate;


use think\Validate;

/**
 * Class Banner
 * @package app\admin\validate
 */
class Banner extends Validate
{
    //验证规则
    protected $rule = [
      'banner_title' => 'require|checkEmpty',
      'banner_url'      => 'require|checkEmpty|url',
      'banner_id'      => 'require',
      'banner_img'      => 'require|checkEmpty'
    ];

    //错误消息
    protected $message = [
        'banner_title'    => '标题不能为空',
        'banner_url.require'    => '参数错误',
        'banner_url.checkEmpty'    => '链接不能为空',
        'banner_url.url' => '链接格式错误',
        'banner_id' => 'Banner_id不能为空',
        'banner_img' => '图片不能为空'
    ];

    //验证场景
    protected $scene = [
        'add'  => ['banner_title', 'banner_url','banner_img'],
        'edit' => ['banner_title', 'banner_url','banner_id','banner_img'],
        'del'  => ['banner_id']
    ];


    protected function checkEmpty($value)
    {
        if (is_string($value)) {
            $value = trim($value);
        }
        if (empty($value)) {
            return false;
        }
        return true;
    }
}